package com.example.myapplication.db.domain;

import com.example.myapplication.R;

import java.io.Serializable;
import java.sql.ResultSet;

public class AccountBean implements Serializable {
    private Float money;
    private int year;
    private int month;
    private int day;
    private String type;
    private String remark;
    private String in_out;
    private int user_id;

    public AccountBean(){};

    private int[] out_icon = {R.drawable.meal,R.drawable.shop,R.drawable.daily,R.drawable.transport,R.drawable.fruit,
            R.drawable.snakes,R.drawable.sport,R.drawable.entertainment,R.drawable.phone,R.drawable.cloth,R.drawable.beauty,
            R.drawable.social,R.drawable.travel,R.drawable.digit,R.drawable.hospital,R.drawable.study,R.drawable.dog,
            R.drawable.redbag,R.drawable.gift,R.drawable.book,R.drawable.fix,R.drawable.donate,R.drawable.icon_package,
            R.drawable.setting
    };
    // 名字数据
    private String[] out_iconName = {"餐饮","购物","日用","交通","水果","零食","运动","娱乐","通讯","服饰","美容"
            ,"社交","旅行","数码","医疗","学习","宠物","礼金","礼物","书籍","维修","捐赠","快递","设置"
    };
    // 图片数据
    private int[] in_icon = {R.drawable.wages,R.drawable.parttime,R.drawable.money_management,R.drawable.redbag,
            R.drawable.more,R.drawable.setting
    };
    // 名字数据
    private String[] in_iconName = {"工资","兼职","理财","礼金","其他","设置"
    };

    public AccountBean(Float money, int year, int month, int day, String type, String remark, String in_out, int user_id) {
        this.money = money;
        this.in_out = in_out;
        this.type = type;
        this.remark = remark;
        this.year = year;
        this.month = month;
        this.day = day;
        this.user_id = user_id;
    }

    public int getImage(int index){
        if (index < 100)
            return out_icon[index];
        else
            return in_icon[index/100];
    }

    //  获取图片的id
    public int getIndex(String type){
        for (int i=0;i<out_iconName.length;i++){
            if (type.equals(out_iconName[i]))
                return i;
        }
        for (int i=0;i<in_iconName.length;i++){
            if (type.equals(in_iconName[i]))
                return i * 100;
        }

        return -1;
    }

    public Float getMoney() {
        return money;
    }

    public void setMoney(Float money) {
        this.money = money;
    }

    public String getIn_out() {
        return in_out;
    }

    public void setIn_out(String in_out) {
        this.in_out = in_out;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public int getUser_id() {
        return user_id;
    }

    public void setUser_id(int user_id) {
        this.user_id = user_id;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public static AccountBean toObject(ResultSet resultSet) {
        try {
            return new AccountBean(
                    resultSet.getFloat("money"),
                    resultSet.getInt("year"),
                    resultSet.getInt("month"),
                    resultSet.getInt("day"),
                    resultSet.getString("type"),
                    resultSet.getString("remark"),
                    resultSet.getString("in_out"),
                    resultSet.getInt("user_id")
            );
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
